layui
    .config({
        base: '../layui/exts/', //静态资源所在路径
    })
    .use(['table', 'form', 'util'], function () {
        var $ = layui.$;
        var form = layui.form;
        var util = layui.util;
        var table = layui.table;

        form.render();
        getData();

        function getData(value) {
            let values = {};
            if (value != '' || value != undefined) {
                values = value
            }
            table.render({
                elem: '#dataTable'
                , url: '/system/getExamineLog'
                , contentType: "application/json"
                , method: 'post'
                , page: true
                , limit: 50
                , height: 'full-65'
                , loading: true
                , where: values
                , size: 'sm'
                , cols: [
                    [
                        {field: 'model', title: '类别', fixed: 'left', width: 80, templet: "#modelTpl"},
                        {field: 'info', title: '信息'},
                        {field: 'createUser', title: '创建人', width: 100},
                        {field: 'createTime', title: '创建时间', width: 140},
                        {fixed: 'right', title: '操作', width: 80, toolbar: '#operationBar'}
                    ]
                ],
            });
        }

        // 提交事件
        form.on('submit(findData)', function (obj) {
            getData(obj.field);
            return false;
        });
        //监听工具条
        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "Approval":
                    top.layer.confirm('确定批准当前选择的审查信息吗？ ', function (index) {
                        $.ajax({
                            url: '../system/securityExamineApproval', //url
                            contentType: "application/json",
                            dataType: 'json', //数据格式
                            type: 'POST', //请求方式
                            async: false, //是否异步请求
                            data: JSON.stringify({id: data.id}),
                            success: function (result) {
                                if (result.code == 0) {
                                    table.reload('dataTable');
                                    layer.close(index);
                                    top.parent.layer.msg(result.message, {icon: 1});
                                } else {
                                    top.parent.layer.alert(result.message, {icon: 2});
                                }
                            },
                        });
                    });
                    return false;
                case 'denial':
                    top.layer.prompt({title: '请输入拒绝原因：', formType: 2}, function (reason, index) {

                        $.ajax({
                            url: '../system/securityExamineDenial', //url
                            contentType: "application/json",
                            dataType: 'json', //数据格式
                            type: 'POST', //请求方式
                            async: false, //是否异步请求
                            data: JSON.stringify({id: data.id, reason: reason}),
                            success: function (result) {
                                if (result.code == 0) {
                                    table.reload('dataTable');
                                    top.layer.close(index);
                                    top.parent.layer.msg(result.message, {icon: 1});
                                } else {
                                    top.parent.layer.alert(result.message, {icon: 2});
                                }
                            },
                        });
                    });
                    return false;

            }
        });
    });